package com.magenta.maxoptra.routing.concepts;

import java.util.Arrays;

/*
* Project: MaxOptRA v1.1
* User: Ivan Usalko
* Date: 08.05.2009 13:46:38
*
* Copyright (c) 1999-2009 Magenta Corporation Ltd. All Rights Reserved.
* Magenta Technology proprietary and confidential.
* Use is subject to license terms.
*/
public final class FloatKey4 {
    final float key0;
    final float key1;
    final float key2;
    final float key3;

    public FloatKey4(float key0, float key1, float key2, float key3) {
        this.key0 = key0;
        this.key1 = key1;
        this.key2 = key2;
        this.key3 = key3;
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof FloatKey4 &&
                key0 == ((FloatKey4) obj).key0 &&
                key1 == ((FloatKey4) obj).key1 &&
                key2 == ((FloatKey4) obj).key2 &&
                key3 == ((FloatKey4) obj).key3;
    }

    @Override
    public int hashCode() {
        int i0 = Float.floatToRawIntBits(key0);
        //CYCLIC SHIFTS.
        int result = ((i0 >>> 5) | (i0 << 32 - 5)) ^ Float.floatToRawIntBits(key1);
        result = ((result >>> 11) | (result << 32 - 11)) ^ Float.floatToRawIntBits(key2);
        return ((result >>> 23) | (result << 32 - 23)) ^ Float.floatToRawIntBits(key3);
        //return (key0 >> 4 ^ key2) | (key1 ^ key3);
    }

    public static void main(String[] args) {
        FloatKey4 keyA = new FloatKey4(2.1f, -2.1f, 4.3f, -4.3f);
        FloatKey4 keyB = new FloatKey4(2.1f, -2.11f, 4.3f, -4.3f);
        System.out.println("KEYA AND KEYB IS EQUALS? " + keyA.equals(keyB));
        System.out.println("KeyA hash = " + keyA.hashCode());
        System.out.println("KeyB hash = " + keyB.hashCode());
        keyA = new FloatKey4(0f, 0f, 0f, 0f);
        keyB = new FloatKey4(1f, 0f, 0f, 0f);
        System.out.println("KEYA AND KEYB IS EQUALS? " + keyA.equals(keyB));
        System.out.println("KeyA hash = " + keyA.hashCode());
        System.out.println("KeyB hash = " + keyB.hashCode());
    }

    @Override
    public String toString() {
        return Arrays.toString(new float[]{key0, key1, key2, key3});
    }
}